﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;

namespace HYView
{
	public partial class DlgSetCorp : System.Windows.Forms.Form
	{
		public DlgSetCorp(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.View view, IList<Element> corpList)
		{
			this.mDoc = doc;
			this.mView = view;
			this.mCorpList = corpList;
			this.InitializeComponent();
			this.comboBox1.Items.Clear();
			foreach (Element item in this.mCorpList)
			{
				this.comboBox1.Items.Add(item);
			}
			if (this.comboBox1.Items.Count > 0)
			{
				this.comboBox1.SelectedIndex = 0;
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.comboBox1.SelectedItem != null)
			{
				Element element = (Element)this.comboBox1.SelectedItem;
				Transaction transaction = new Transaction(this.mDoc, "SetCorp");
				try
				{
					transaction.Start();
					this.mView.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(element.Id);
					transaction.Commit();
				}
				catch
				{
					transaction.RollBack();
				}
				base.Close();
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private Document mDoc;

		private Autodesk.Revit.DB.View mView;

		private IList<Element> mCorpList;
	}
}
